<?php
/**
 * This file is part of League of Legends PHP Inibin Parser.
 *
 * League of Legends PHP Inibin Parser is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * League of Legends PHP Inibin Parser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with League of Legends PHP Inibin Parser.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * League of Legends Client-Database parser
 * Class: champion
 *
 * @author Marcel Klimek <klimek@secondred.de>
 * @copyright Marcel Klimek
 * @version 0.1.3
 */

require_once('enums/enum.champion.php');
class champion
{
    /**
     * Instance of Class parser
     * @var parser
     * @access private
     */
    private $objParser = null;

    /**
     * Instance of Class SQL
     * @var mysql
     */
    private $objSQL = null;

    
    /**
     * Constructor, which will save an instance of the parser class
     *
     * @param parser $objParser
     * @access public
     */
    public function __construct($objParser, $objSQL)
    {
        $this->objParser = $objParser;
        $this->objSQL = $objSQL;
        //$this->doQuery();
    }


    /**
     * Returns the Base Damage of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getBaseDamage()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_DAMAGE);
    }


    /**
     * Returns the Base HP of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getBaseHP()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_HP);
    }


    /**
     * Returns the Base Mana of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getBaseMana()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_MANA);
    }


    /**
     * Returns the Base Armor of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getBaseArmor()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_ARMOR);
    }


    /**
     * Returns the Base Magic Armor of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getBaseMagicArmor()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_MAGICARMOR);
    }


    /**
     * Returns the Base HP Regeneration of the current Champion
     *
     * @return float
     * @access public
     */
    public function getBaseHPReg()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_HPREG);
    }


    /**
     * Returns the Base Mana Regeneration of the current Champion
     *
     * @return float
     * @access public
     */
    public function getBaseMPReg()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_MPREG);
    }


    /**
     * Returns the Base RunSpeed of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getBaseRunSpeed()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_RUNSPEED);
    }


    /**
     * Returns the Per Lvl Armor Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlArmor()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_ARMOR);
    }


    /**
     * Returns the Per Lvl Damage Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlDamage()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_DAMAGE);
    }


    /**
     * Returns the Per Lvl HP Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlHP()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_HP);
    }


    /**
     * Returns the Per Lvl HP Regeneration Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlHPReg()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_HPREG);
    }


    /**
     * Returns the Per Lvl Magic Armor Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlMagicArmor()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_MAGICARMOR);
    }


    /**
     * Returns the Per Lvl Mana Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlMana()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_MANA);
    }


    /**
     * Returns the Per Lvl Mana Regeneration Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlMPReg()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_MPREG);
    }


    /**
     * Returns the Description of the current Champion
     *
     * @return string
     * @access public
     */
    public function getDescription()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_DESCRIPTION);
    }


    /**
     * Returns the Range of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getRange()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_RANGE);
    }


    /**
     * Returns the Skill 1 of the current Champion
     *
     * @return string
     * @access public
     */
    public function getSkill1()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_SKILL_1);
    }


    /**
     * Returns the Skill 2 of the current Champion
     *
     * @return string
     * @access public
     */
    public function getSkill2()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_SKILL_2);
    }


    /**
     * Returns the Skill 3 of the current Champion
     *
     * @return string
     * @access public
     */
    public function getSkill3()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_SKILL_3);
    }


    /**
     * Returns the Skill 4 of the current Champion
     *
     * @return string
     * @access public
     */
    public function getSkill4()
    {
        return $this->objParser->getValue(ChampionEnum::CHAMPION_SKILL_4);
    }


    /**
     * Returns the (mapped) name of the champion
     *
     * @return string
     * @access public
     */
    public function getName()
    {
        $strFilename = $this->objParser->getFilename();
        if (array_key_exists($strFilename, ChampionEnum::$CHAMPION_MAPPING_NAME))
            return ChampionEnum::$CHAMPION_MAPPING_NAME[$strFilename];
        else
            return $strFilename;
    }


    /**
     * Returns the Base Attack Speed
     *
     * @return string
     * @access public
     */
    public function getBaseAttackSpeed()
    {
        return (0.625 * (1.0 - $this->objParser->getValue(ChampionEnum::CHAMPION_BASE_ASPEED)));
    }


    /**
     * Returns the Per Lvl Attack Speed Amount of the current Champion
     *
     * @return integer,long
     * @access public
     */
    public function getLvlAttackSpeed()
    {
        return 0.01 * $this->objParser->getValue(ChampionEnum::CHAMPION_LVL_ASPEED);
    }



    /**
     * This Method will echo a full data-sheet of the current champion stats
     *
     * @access public
     */
    public function getOutput()
    {
        echo 'Champion: '   . $this->getName()          . '<br/>';
        echo 'DPS LVL 18: '    . (($this->getBaseDamage() + (18 * $this->getLvlDamage()))  *  ($this->getBaseAttackSpeed() *  (1 + (18 * $this->getLvlAttackSpeed()))))    . '<br/>';
        echo 'ASpeed: '    . $this->getBaseAttackSpeed()    . ' Pro Lvl: ' . $this->getLvlAttackSpeed() . '<br/>';
        echo 'Schaden: '    . $this->getBaseDamage()    . ' Pro Lvl: ' . $this->getLvlDamage() . '<br/>';
        echo 'Leben: '      . $this->getBaseHP()        . ' Pro Lvl: ' . $this->getLvlHP() . '<br/>';
        echo 'Mana: '       . $this->getBaseMana()      . ' Pro Lvl: ' . $this->getLvlMana() . '<br/>';
        echo 'RunSpeed: '   . $this->getBaseRunSpeed()  . '<br/>';
        echo 'Armor: '      . $this->getBaseArmor()     . ' Pro Lvl: ' . $this->getLvlArmor() . '<br/>';
        echo 'Magic Armor: '. $this->getBaseMagicArmor(). ' Pro Lvl: ' . $this->getLvlMagicArmor() . '<br/>';
        echo 'HP Reg: '     . $this->getBaseHPReg()     . ' Pro Lvl: ' . $this->getLvlHPReg() . '<br/>';
        echo 'MP Reg: '     . $this->getBaseMPReg()     . ' Pro Lvl: ' . $this->getLvlMPReg() . '<br/>';
        echo 'Range: '      . $this->getRange()         . '<br/>';
        echo 'Beschreibung: '. $this->getDescription()  . '<br/>';
        echo 'Skill 1: '    . $this->getSkill1()        . '<br/>';
        echo 'Skill 2: '    . $this->getSkill2()        . '<br/>';
        echo 'Skill 3: '    . $this->getSkill3()        . '<br/>';
        echo 'Skill 4: '    . $this->getSkill4()        . '<br/>';
    }


    /**
     * This Method is used to execute some SQL-Queries
     * 
     * To use this method, just uncomment the call in the constructor
     * or call it manually ;)
     */
    public function doQuery()
    {
        //insert into db
        $this->objSQL->safe_query("INSERT INTO champions (`name`
                                                          ,`base_damage`
                                                          ,`base_hp`
                                                          ,`base_mana`
                                                          ,`base_armor`
                                                          ,`base_magicarmor`
                                                          ,`base_hpreg`
                                                          ,`base_mpreg`
                                                          ,`base_attackspeed`
                                                          ,`lvl_damage`
                                                          ,`lvl_hp`
                                                          ,`lvl_mana`
                                                          ,`lvl_armor`
                                                          ,`lvl_magicarmor`
                                                          ,`lvl_hpreg`
                                                          ,`lvl_mpreg`
                                                          ,`lvl_attackspeed`
                                                          ,`runspeed`
                                                          ,`range`
                                                          ,`description`)
                                    VALUES ('".mysql_real_escape_string($this->getName())."'
                                            ,'".$this->getBaseDamage()."'
                                            ,'".$this->getBaseHP()."'
                                            ,'".$this->getBaseMana()."'
                                            ,'".$this->getBaseArmor()."'
                                            ,'".$this->getBaseMagicArmor()."'
                                            ,'".$this->getBaseHPReg()."'
                                            ,'".$this->getBaseMPReg()."'
                                            ,'".$this->getBaseAttackSpeed()."'
                                            ,'".$this->getLvlDamage()."'
                                            ,'".$this->getLvlHP()."'
                                            ,'".$this->getLvlMana()."'
                                            ,'".$this->getLvlArmor()."'
                                            ,'".$this->getLvlMagicArmor()."'
                                            ,'".$this->getLvlHPReg()."'
                                            ,'".$this->getLvlMPReg()."'
                                            ,'".$this->getLvlAttackSpeed()."'
                                            ,'".$this->getBaseRunSpeed()."'
                                            ,'".$this->getRange()."'
                                            ,'".mysql_real_escape_string($this->getDescription())."')");

    }
}
?>